<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <!-- 缺点 提交之后跳转 不利于用户体验 -->
    <form action="http://ajax-api.itheima.net/api/data" method="post">
        <input type="text" class="username" name="username" placeholder="请输入用户名" />
        <!-- 必须加上name才能得到接口返回的数据 -->
        <br />
        <input type="text" name="food" placeholder="请输入喜欢的食物" />
        <br />
        <input type="textarea" name="sign" placeholder="请输入个性签名" />
        <br />
        <button type="submit">提交</button>
    </form>
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
    <script>
        document.querySelector('form').addEventListener('submit', function (e) {
            e.preventDefault()
            //发起axios
            axios({
                url: 'http://ajax-api.itheima.net/api/data',
                method: 'post',
                data: {
                    username: document.querySelector('.username').value,
                    food: document.querySelector('[name=food]').value,
                    sign: document.querySelector('[name=sign]').value,

                }
            }).then((res) => {
                console.log(res);
            })
        })
    </script>
</body>

</html>